package com.guanyong.admin.controllers.api;

import com.guanyong.admin.handle.GlobleData;
import com.guanyong.model.HistoryTodayModel;
import com.guanyong.utils.Comm.ResultCode;
import com.guanyong.utils.Comm.ResultObject;
import com.qiniu.common.Zone;
import com.qiniu.storage.BucketManager;
import com.qiniu.storage.Configuration;
import com.qiniu.storage.model.FileInfo;
import com.qiniu.util.Auth;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.HashSet;
import java.util.Set;

/**
 * Created by Administrator on 2017/8/29 0029.
 */
@RestController
@RequestMapping("/api/demo/")
public class DemoApi {

    @Autowired
    GlobleData globleData;


    @RequestMapping(value = "filmevaluateUP", method = RequestMethod.POST)
    ResultObject<String> filmevaluateUP(HttpServletRequest request){
        ResultObject<String> resultObject=new ResultObject<String>();

            resultObject.setCode(ResultCode.OperateOk);
        resultObject.setResult("http://101.201.122.79:8083/Images/upload/defalut/user_defalut.png");

        return  resultObject;
    }


//七牛电影支援列表
    public static void main(String[] args) {

        Configuration cfg = new Configuration(Zone.zone0());
//...其他参数参考类注释
//        String accessKey = globleData.QiNiu_Ak;
//        String secretKey = globleData.Qiniu_SK;
        String accessKey = "SkEwh-W9aETkg509u5gQaTHLC4l5ypXy6gH2ZRxT";
        String secretKey = "NOUeWrbb6qMZjUkdd8_EfsOSAA5ZVF5FgMVOeAsE";
        String bucket = "voideapp";
        Auth auth = Auth.create(accessKey, secretKey);
        BucketManager bucketManager = new BucketManager(auth, cfg);
//文件名前缀
//每次迭代的长度限制，最大1000，推荐值 1000
        int limit = 1000;
//指定目录分隔符，列出所有公共前缀（模拟列出目录效果）。缺省值为空字符串
        String delimiter = "";
//列举空间文件列表
        BucketManager.FileListIterator fileListIterator = bucketManager.createFileListIterator(bucket, "", limit, delimiter);
        Set<String> newSet = new HashSet<String>();
        while (fileListIterator.hasNext()) {
            //处理获取的file list结果
            FileInfo[] items = fileListIterator.next();
            for (FileInfo item : items) {
                if(item.key.endsWith(".mp4")){
                    System.out.println(item.key);
                    newSet.add(item.key);
                }
            }
        }
    }
}

